Write-Host "启动用户服务..."
Write-Host

Set-Location "$PSScriptRoot/../../apps/services/user-service"

# 检查Java环境
try {
    java -version > $null 2>&1
}
catch {
    Write-Host "错误: 未找到Java环境，请确保已安装JDK 21+"
    Read-Host -Prompt "按任意键退出"
    exit 1
}

# 检查Maven环境
try {
    mvn -version > $null 2>&1
}
catch {
    Write-Host "错误: 未找到Maven环境，请确保已安装Maven 3.8+"
    Read-Host -Prompt "按任意键退出"
    exit 1
}

Write-Host "正在编译项目..."
$mvnCompile = Start-Process mvn -ArgumentList 'clean', 'compile' -NoNewWindow -Wait -PassThru
if ($mvnCompile.ExitCode -ne 0) {
    Write-Host "编译失败，请检查错误信息"
    Read-Host -Prompt "按任意键退出"
    exit 1
}

Write-Host "启动服务..."
Start-Process mvn -ArgumentList 'spring-boot:run' -NoNewWindow

Read-Host -Prompt "按任意键退出" 